﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
using WorkFlowCore.EventHandlers;
using WorkFlowCore.Framework.EventHandlers;
using WorkFlowCore.Framework.Repositories;
using WorkFlowCore.IRepositories;
using WorkFlowCore.Workflows;
using WorkFlowCore.WorkTasks;

namespace WorkFlowCore.Framework
{
    public static class WorkFlowCoreFrameworkService
    {
        /// <summary>
        /// orm类型，目前暂时只支持本地文件，后续考虑增加 Ef 、sqlsuger 的支持
        /// </summary>
        public enum FrameworkConfigOrmType
        {
            Default,
        }
        public class FrameworkConfig
        {
            public FrameworkConfigOrmType OrmType { get; set; } = FrameworkConfigOrmType.Default;
        }
        public static void AddWorkFlowCoreFramework(this IServiceCollection services,Action<FrameworkConfig> config=null)
        {
            var conf = new FrameworkConfig();
            config?.Invoke(conf);
            if (conf.OrmType== FrameworkConfigOrmType.Default)
            {
                services.AddScoped(typeof(IBasicRepository<,>), typeof(BasicRepository<,>));
                services.AddScoped(typeof(IBasicRepository<>), typeof(BasicRepository<>));
            }

            
            //事件处理
            services.AddScoped<SendTaskEventHandler>();
            services.AddScoped<TaskFinishedEventHandler>();

            var assembly = typeof(WorkFlowCoreFrameworkService).Assembly;
            EventManager.RegisterSubscriptions(assembly);

        }
    }
}
